import {resolve} from "node:path";

const Path = require('path');
const vuePlugin = require('@vitejs/plugin-vue')
const { defineConfig } = require('vite');
import Components from 'unplugin-vue-components/vite';
import {AntDesignVueResolver} from 'unplugin-vue-components/resolvers';
import autoImport from 'unplugin-auto-import/vite'
import VueSetupExtend from 'vite-plugin-vue-setup-extend'
import {loadEnv} from "vite";
const CWD = process.cwd();

export default ({ command, mode }) => {
  const { VITE_BASE_URL, VITE_DROP_CONSOLE, VITE_MOCK_IN_PROD } = loadEnv(mode, CWD);

    return defineConfig({
    root: Path.join(__dirname, 'src', 'renderer'),
    base:'/',
    publicDir: 'public',
    resolve: {
        alias: [
            {
                find: '@',
                replacement: resolve(__dirname, './src'),
            },
        ],
    },
    css: {
        preprocessorOptions: {
            less: {
                javascriptEnabled: true,
                modifyVars: {},
                // additionalData: `
                //   @import '@/styles/variables.less';
                // `,
            },
        },
    },
    plugins: [vuePlugin(),
        Components({
            resolvers: [
                AntDesignVueResolver({
                    importStyle: false, // css in js
                }),
            ],
        }), autoImport({
            imports: [
                'vue',
                'vue-router',
                'pinia'
            ],
            dts: false
        }), VueSetupExtend],
    server: {
        host: '0.0.0.0',
        port: 8080,
        open: true,
      proxy: {
        '^/backend': {
          // target: 'https://nest-admin.buqiyuan.top/upload',
          // target: 'http://127.0.0.1:9567',
            target: 'http://127.0.0.1:9669',
          changeOrigin: true,
          rewrite: (path) => path.replace(new RegExp(`^/backend`), ''),
        },
      },
    },
        lintOnSave: false
});

}



